﻿using System;

namespace TestByWire.Factories.StubbingStrategies
{
    internal abstract class StubStrategyBase : IStubCreationStrategy
    {
        public abstract bool RegisterOnContainer { get; }
        public abstract bool CanHandleType(Type type, string instanceName);
        public virtual bool CompletesBuild { get { return false; } }
        
        public object CreateInstance(Type type, string instanceName)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (!CanHandleType(type, instanceName))
            {
                throw new InvalidOperationException("Provided type can not be handled by stub strategy.");
            }

            return TryCreateInstance(type);
        }

        protected abstract object TryCreateInstance(Type type);

    }
}
